package easy;

public class Solution_2006 {

    public int countKDifference(int[] nums, int k) {
        int[] counts = new int[101];
        for (int num : nums) {
            counts[num]++;
        }
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            int sub = k + nums[i];
            if (sub <= 100) {
                count += counts[sub];
            }
        }
        return count;
    }

    public static void main(String[] args) {
        Solution_2006 model = new Solution_2006();
        System.out.println(model.countKDifference(new int[]{1, 2, 2, 1}, 1));
        System.out.println(model.countKDifference(new int[]{1, 3}, 3));
        System.out.println(model.countKDifference(new int[]{3, 2, 1, 5, 4}, 2));
    }
}
